package com.pethospital.controller;

import com.pethospital.common.Result;
import com.pethospital.dto.VaccineDTO;
import com.pethospital.entity.Vaccine;
import com.pethospital.service.MedicalRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * 疫苗记录控制器
 */
@RestController
@RequestMapping("/vaccine")
@Slf4j
public class VaccineController {

    @Resource
    private MedicalRecordService medicalRecordService;

    /**
     * 添加疫苗记录
     */
    @PostMapping
    public Result<Long> addVaccineRecord(@RequestBody @Valid VaccineDTO vaccineDTO, HttpServletRequest request) {
        Long userId = (Long) request.getAttribute("userId");
        log.info("添加疫苗记录, 用户ID: {}, 数据: {}", userId, vaccineDTO);
        
        Long vaccineId = medicalRecordService.addVaccineRecord(vaccineDTO, userId);
        return Result.success(vaccineId);
    }

    /**
     * 获取宠物疫苗记录列表
     */
    @GetMapping("/pet/{petId}")
    public Result<List<Vaccine>> getVaccineRecordsByPetId(@PathVariable Long petId) {
        log.info("获取宠物疫苗记录列表, 宠物ID: {}", petId);
        
        List<Vaccine> vaccines = medicalRecordService.getVaccineRecordsByPetId(petId);
        return Result.success(vaccines);
    }
} 